<?php
namespace Company\Controller;
use Think\Controller;
class MovegoodsController extends BaseController {
    public function _initialize()
    {
        parent::_initialize();
        $g=session('company');
		C('erp_dbname',$g['db']);
        $db_name=$g['db'];
		//数据库连接基础配置-begin
		C('db_config.DB_TYPE',C('DB_TYPE'));
		C('db_config.DB_HOST',C('DB_HOST'));
		C('db_config.DB_USER',C('DB_USER'));
		C('db_config.DB_PWD',C('DB_PWD'));
		C('db_config.DB_PORT',C('DB_PORT'));
		C('db_config.DB_CHARSET',C('DB_CHARSET'));
		C('db_config.DB_NAME',C('erp_dbname'));
		//数据库连接基础配置-end
		
		//加载自定义配置信息
		$m=M('Config','erp_',C('db_config'));
		$list=$m->where(array('status'=>1))->getField('en_name,value');
		C('base_config',$list);
    }
	//推送货主erp审核
	public function push_merchant_erp($movegoods,$movegoodsinfo,$merchant_code){
		$u=M('User');
		$map_u=[];
		$map_u['owner_code']=$merchant_code;
		$u_info=$u->where($map_u)->find();
		$username=$u_info['username'];
		$db_name=C('DB_PREFIX_T').$username;
		C('db_config.DB_NAME',$db_name);

		$m=M('MovegoodsInfo', "erp_", C('db_config'));
		$n=M('Movegoods', "erp_", C('db_config'));
		
		//当日流水号生成
		$map=[];
		$map['_string']="add_time-UNIX_TIMESTAMP(DATE(NOW()))>0 and add_time-UNIX_TIMESTAMP(DATE(NOW()))<86400";
		$count=$n->where($map)->count();//当天添加的调拨单数
		//echo $m->getlastsql();
		$count=$count+1;
		$serial_number="";
		if($count<10){
			$serial_number='0000'.strval($count);
		}
		if($count>=10 and $count<100){
			$serial_number='000'.$count;
		}
		if($count>=100 and $count<1000){
			$serial_number='00'.$count;
		}
		if($count>=1000 and $count<10000){
			$serial_number='0'.$count;
		}
		$movegoods['old_order_no']=$movegoods['order_no'];
		//重定义订单号
		$movegoods['order_no']="OWN".date("Ymd",time()).$serial_number;
		unset($movegoods['id']);
		
		$has=$n->where(['old_order_no'=>$movegoods['order_no']])->count();
		if(!$has){
			unset($movegoods['own_status']);
			$movegoods['old_merchant_code']=C("base_config.merchant_code");
			$addid=$n->add($movegoods);
			if(!$addid){
				alert(0,"调拨单推送货主失败");
			}
			foreach($movegoodsinfo as $k=>$v){
				$v['order_id']=$addid;
				unset($v['id']);
				$res=$m->add($v);
				
				if(!$res){
					alert(0,"调拨单推送货主失败!");
				}
			}
		}else{
			//更新
			foreach($movegoodsinfo as $k=>$v){
				unset($v['order_id']);
				$res=$m->where(['goods_no'=>$v['goods_no']])->save($v);
				if($res===false){
					alert(0,"调拨单推送货主失败!");
				}
			}
		}
		
		
		
	}
	//审核不通过
	public function examined_erp(){
		
		$u=M('User');
		$ids=I('ids');
		$n=M('Movegoods', "erp_", C('db_config'));
		$m=M('MovegoodsInfo', "erp_", C('db_config'));
		
		
		
		$own_status=$n->where(['id'=>$ids[0]])->find();
		if($own_status['own_status']){
			alert(0,"自己的单子不能审核");
		}
		if($own_status['status']==1){
			alert(0,"已审核通过不能修改");
		}
		

		$map_u=[];
		$map_u['owner_code']=$own_status['old_merchant_code'];
		$u_info=$u->where($map_u)->find();
		
		$username=$u_info['username'];
		$db_name=C('DB_PREFIX_T').$username;
		C('db_config.DB_NAME',$db_name);
		
		$mv=M('Movegoods', "erp_", C('db_config'));
		$res=$mv->where(['order_no'=>$own_status['old_order_no']])->save(["status"=>2]);
		// echo $mv->_sql();
		// die;
		if($res!==false){
			$n->where(['id'=>$ids[0]])->save(["status"=>2]);
			alert(1,"审核成功");
		}else{
			alert(0,"审核失败");
		}
		
	}
	//审核通过-审核并推送oms
	public function examined_oms(){
		$ids=I('ids');
		
		$n=M('Movegoods', "erp_", C('db_config'));
		$map=[];
		$map['id']=$ids[0];
		
		$own_status=$n->where(['id'=>$ids[0]])->getField('own_status');
		if($own_status){
			alert(0,"自己的单子不能审核");
		}
		$n_info=$n->field('old_order_no')->where($map)->find();

		if($n_info['status==4']){		//status==4:货主erp已经审核并通过
			alert(0,"已审核不能再次审核");
		}
		
		// C('OMS_URL',"http://oms.dxscp.com");
		$url=C('OMS_URL')."/index.php/Erpapi/Erpapi/examined_receive_movegoods";
		
		$return=push($url,$n_info);
		
		$res=json_decode($return,true);
		
		if($res['flag']){
			$data=[];
			$data['status']=1;
			$n->where($map)->save($data);
			alert(1,"审核通过");
		}else{
			alert(0,$res['tip']);
		}
	}
	//推送oms
	public function push_oms(){
		$ids=I('ids');
		
		$m=M('MovegoodsInfo', "erp_", C('db_config'));
		$n=M('Movegoods', "erp_", C('db_config'));
		$map=[];
		$map['id']=$ids[0];
		
		$n_info=$n->where($map)->find();
		if(!$n_info['own_status']){
			alert(0,"此调拨单不能推送");
		}
		$n_info['merchant_code']=C('BASE_CONFIG.merchant_code');
		if($n_info['push_status'] and $n_info['status']==0){
			alert(0,"已推送不能再次推送");
		}
		if($n_info['status']==1){
			alert(1,"已审核通过不能推送");
		}
		
		$map_info=[];
		$map_info['order_id']=$n_info['id'];
		$m_list=$m->where($map_info)->select();
		//同步货主erp-begin
		$this->push_merchant_erp($n_info,$m_list,$m_list[0]['old_merchant_code']);
		//同步货主erp-end
		$n_info['detail']=$m_list;
		foreach($m_list as $k=>$v){
			if(!$v['amount']){
				alert(0,$v['goods_no']."商品数量不能为0");
			}
		}
		
		// C('OMS_URL',"http://oms.dxscp.com");
		$url=C('OMS_URL')."/index.php/Erpapi/Erpapi/receive_movegoods.html";
		
		// dump($url);
		$return=push($url,$n_info);
		// dump($return);
		// die;
		$res=json_decode($return,true);
		
		if($res['flag']){
			$data=[];
			$data['push_status']=1;
			
			$n->where($map)->save($data);
			alert(1,"推送成功");
		}else{
			alert(0,$res['tip']);
		}
	}
	
	public function edit_nums(){
		$param=I('param.','','trim');
		$id=$param['id'];
		$m=M('MovegoodsInfo', C('DB_PREFIX_T'), C('db_config'));
		$n=M('Movegoods', C('DB_PREFIX_T'), C('db_config'));
		$order_id=$m->where(['id'=>$id])->getField('order_id');
		$status=$n->where(['id'=>$order_id])->getField('status');
		if($status==1){
			alert(0,"已经审核通过，不能修改!");
		}
		$res=$m->where(['id'=>$id])->save(['amount'=>$param['amount']]);
		// dump($param);
		// die;
		if($res!==false){
			alert(1,"修改成功");
		}else{
			alert(0,"修改失败");
		}
	}
	//删除详情
	public function del_movegoodsinfo(){
		
		$id=trim(I('id'));

		$m=M('MovegoodsInfo', C('DB_PREFIX_T'), C('db_config'));
		$res=$m->where(['id'=>$id])->delete();
		
		if($res!==false){
            echo "y";
        }else{
            echo "操作失败";
        }
	}
	
	//确认添加
	public function confirm_add(){
		$param=I();
		$manua_id_list=$param['manua_id'];
		$goods_no_list=$param['goods_no'];
		$goods_name_list=$param['goods_name'];
		$bar_code_list=$param['bar_code'];
		$merchant_code_list=$param['merchant_code'];
		
		$old_merchant_code=$merchant_code_list[0];
		
		foreach($merchant_code_list as $ks=>$vs){

			if($vs!=$old_merchant_code){
				alert(0,"一个调拨单只能调拨一个货主的货！");
			}
			$old_merchant_code=$vs;
			
		}
		$trans = M('',C('DB_PREFIX_T'), C('db_config'));
		$trans->startTrans();   // 开启事务
		
		$m=M('MovegoodsInfo', C('DB_PREFIX_T'), C('db_config'));
		// $manua_id=explode(",",$manua_id_list);
		// $goods_no=explode(",",$goods_no_list);
		// $goods_name=explode(",",$goods_name_list);
		// $bar_code=explode(",",$bar_code_list);
		// $merchant_code=explode(",",$merchant_code_list);
		
		foreach($manua_id_list as $k=>$v){
			$data=[];
			$data['manua_id']=$v;
			$data['goods_no']=$goods_no_list[$k];
			$data['goods_name']=$goods_name_list[$k];
			$data['bar_code']=$bar_code_list[$k];
			$data['order_id']=$param['order_id'];
			$data['old_merchant_code']=$merchant_code_list[$k];
			
			$has=$m->where(['goods_no'=>$goods_no_list[$k],'order_id'=>$param['order_id']])->count();
			if($has){
				$trans->rollback();
				alert(0,$goods_no_list[$k]."已添加过了!");
			}
			$res=$m->add($data);
			if(!$res){
				$trans->rollback();
				alert(0,$goods_no_list[$k]."添加失败");
			}
		}
		
		$trans->commit();
		alert(1,"添加成功");
	}
	
	//常用列表
	public function tslist(){
		$Book=M('Book', C('DB_PREFIX_T'), C('DB_TYPE') . '://' . C('DB_USER') . ':' . C('DB_PWD') . '@' . C('DB_HOST') . ':' . C('DB_PORT') . '/' . C('erp_dbname'));
		$Section=M('Section', C('DB_PREFIX_T'), C('DB_TYPE') . '://' . C('DB_USER') . ':' . C('DB_PWD') . '@' . C('DB_HOST') . ':' . C('DB_PORT') . '/' . C('erp_dbname'));
		$Personnel=M('Personnel', C('DB_PREFIX_T'), C('DB_TYPE') . '://' . C('DB_USER') . ':' . C('DB_PWD') . '@' . C('DB_HOST') . ':' . C('DB_PORT') . '/' . C('erp_dbname'));
		$ContactsCompany=M('ContactsCompany', C('DB_PREFIX_T'), C('DB_TYPE') . '://' . C('DB_USER') . ':' . C('DB_PWD') . '@' . C('DB_HOST') . ':' . C('DB_PORT') . '/' . C('erp_dbname'));
		$m=M('Movegoods', C('DB_PREFIX_T'), C('DB_TYPE') . '://' . C('DB_USER') . ':' . C('DB_PWD') . '@' . C('DB_HOST') . ':' . C('DB_PORT') . '/' . C('erp_dbname'));
		$book_list=$Book->where(array('examined'=>2))->select();
		$section_list=$Section->select();
		$personnel_list=$Personnel->select();
		$company_list=$ContactsCompany->select();
		//当日流水号生成
		$map['_string']="add_time-UNIX_TIMESTAMP(DATE(NOW()))>0 and add_time-UNIX_TIMESTAMP(DATE(NOW()))<86400";
		$count=$m->where($map)->count();//当天添加的调拨单数
		//echo $m->getlastsql();
		$count=$count+1;
		$serial_number="";
		if($count<10){
			$serial_number='0000'.strval($count);
		}
		if($count>=10 and $count<100){
			$serial_number='000'.$count;
		}
		if($count>=100 and $count<1000){
			$serial_number='00'.$count;
		}
		if($count>=1000 and $count<10000){
			$serial_number='0'.$count;
		}
		$this->assign('serial_number',$serial_number);//流水序号
		$this->assign('book_list',$book_list);
		$this->assign('section_list',$section_list);
		$this->assign('personnel_list',$personnel_list);
		$this->assign('company_list',$company_list);
	}
	//添加商品
	//仓库库存列表
	public function get_warehousebound(){
		$param=I('param.','','trim');
		
		$warehouse_code=$param['warehouse_code'];
		$manua_id=$param['manua_id'];
		$merchant_code=$param['merchant_code'];
		$goods_no=$param['goods_no'];
		$goods_name=$param['goods_name'];
		$bar_code=$param['bar_code'];
		$goods_cate=$param['goods_cate'];
		$status=$param['status'];

		$excel=I('excel');
		if(!empty($warehouse_code)){
			$url_arr['warehouse_code']=$warehouse_code;
		}
		if(!empty($goods_no)){
			$url_arr['goods_no']=$goods_no;
		}
		if(!empty($goods_name)){
			$url_arr['goods_name']=$goods_name;
		}
		if(!empty($bar_code)){
			$url_arr['bar_code']=$bar_code;
		}
		if(!empty($goods_cate)){
			$url_arr['goods_cate']=$goods_cate;
		}
		if(!empty($status)){
			$url_arr['status']=$status;
		}
		if(!empty($manua_id)){
			$url_arr['manua_id']=$manua_id;
		}

		$data['warehouse_code']=$warehouse_code;
		$data['goods_no']=$goods_no;
		$data['goods_name']=$goods_name;
		$data['bar_code']=$bar_code;
		$data['goods_cate']=$goods_cate;
		
		// $data['manua_id']=$manua_id;
		$data['merchant_code']=$merchant_code;
		
		$p=$param['p'];
		$rows=20;
		if(!empty($p)){
			$url_arr['p']=$p;
		}
		if($status==2){
			$rows=5000;
		}
		
		$data['page']=$p;
		$data['rows']=$rows;
		$data['sort']='id';
		$data['order']='desc';

		$excel_url=U('Warehouse/get_warehousebound',$url_arr);
		
		$url=C('BASE_CONFIG.warehousebound');
		$return=push($url,$data);

		$list=json_decode($return,true);
		
		$Page       = new \Think\Page($list['total'],$data['rows']);
        $show       = $Page->show();
		
		$ids=$param['ids'];
		if(!empty($ids)){
			$idss=explode(',',$ids);
			foreach($list['rows'] as $k=>$v){
				foreach($idss as $ks=>$vs){
					if($v['id']==$vs){
						$arr[]=$v;
						break;
					}
				}
			}
			$list['rows']=$arr;
		}
		// dump($list);
		// die;
		$pro=M('product',C('DB_PREFIX_T'),C('db_config'));
		foreach($list['rows'] as $ks=>$vs){
			$list['rows'][$ks]['current_type']=$pro->where(array('goods_no'=>$vs['goods_no']))->getField('currency');
		}
		if($excel){
			foreach($list['rows'] as $ks=>$vs){
				$list['rows'][$ks]['goods_no']=' '.$vs['goods_no'];
				$list['rows'][$ks]['manua_id']=' '.$vs['manua_id'];
				$list['rows'][$ks]['bar_code']=' '.$vs['bar_code'];
			}
			$xlsName  = "商品库存列表";
			$xlsCell  = array(
				array('goods_no','商品编码'),
				array('manua_id','账册编号'),
				array('goods_name','商品名称'),
				array('goods_cate','商品类型'),
				array('bar_code','条形码'),
				array('goods_spec','规格'),
				array('unit1','第一单位'),
				array('unit2','第二单位'),
				array('goods_price','入库平均价格'),
				array('amount','总数量'),
				array('storage_amount','库存数量'),
				array('freez_amount','冻结数量'),
				array('conforming_p','合格品'),
				array('nonconforming_p','残次品'),
				array('scrap_one','报废品'),
				array('push_times','推送次数'),
				array('info_count','批次数量'),
			);
			$Aexcel=A('Order');
			$Aexcel->exportExcel($xlsName,$xlsCell,$list['rows']);
			die;
		}
		
		$this->assign('excel_url',$excel_url);
		$this->assign('page',$show);
		$this->assign('total',$list['total']);
		$this->assign('list',$list['rows']);
		// dump($return);
		$this->display();
	}
	public function movegoodsinfo(){
        $m=M('MovegoodsInfo', C('DB_PREFIX_T'), C('db_config'));
		$n=M('Movegoods', C('DB_PREFIX_T'), C('db_config'));
		$keywords=I('get.keywords');     
		$selval=I('get.selval');
		$id=I('id');
		$p=I('p')?I('p'):1;
		$listrows=20;
		$firstrow=($p-1)*$listrows;
        if(!empty($keywords)){
			if($selval=='1'){
				$map['goods_no'] = array('like','%'.$keywords.'%');
			}
			if($selval=='2'){
				$map['goods_name'] = array('like','%'.$keywords.'%');
			}
			if($selval=='3'){
				$map['bar_code'] = array('like','%'.$keywords.'%');
			}
        }
		$map['order_id']=$id;
		$count=$m->where($map)->count();
		$list=$m->where($map)->limit($firstrow.','.$listrows)->order('id desc')->select();
		
		$own_status=$n->where(['id'=>$id])->getField('own_status');
		if(empty($own_status)){		//申请调拨，查看库存
		
			$storage_url=C('WMS_URL')."/index.php?s=/Goodsapi/get_goodsinfo";
			foreach($list as $k=>$v){
				$send_data=[];
				$send_data['warehouse_code']="11330213";
				$send_data['goods_no']=$v['goods_no'];
				$res_storage=push($storage_url,$send_data);
				
				$res_storage=json_decode($res_storage,true);
				
				$list[$k]['storage_amount']=$res_storage['data'][0]['storage_amount'];
			}
		}
		
		$Page       = new \Think\Page($count,$listrows);// 实例化分页类 传入总记录数和每页显示的记录数(25)
		$show       = $Page->show();// 分页显示输出

		//调拨设置货主信息-begin
		$send_data=[];
		$send_data['merchant_code']=C('base_config.merchant_code');

		// C('OMS_URL',"http://localhost/jdreams/oms");
		$url=C('OMS_URL')."/index.php/Erpapi/Erpapi/movegoods_set";
		
		$res=push($url,$send_data);
		$res=json_decode($res,true);
		if($res['flag']){
			$user_code_str=$res['tip'];
			$this->assign("user_code_str",$user_code_str);
		}
		//调拨设置货主信息-end
		
		$this->assign("own_status",$own_status);
		$this->assign("count",$count);
		$this->assign("list",$list);
		$this->assign('page',$show);// 赋值分页输出
		$this->display();
    }
	
	//调拨明细
	public function movegoodslist(){
		$param=I('param.','','trim');
		
        $m=M('MovegoodsInfo', C('DB_PREFIX_T'), C('db_config'));
		$n=M('Movegoods', C('DB_PREFIX_T'), C('db_config'));
		$keywords=I('get.keywords');     
		$selval=I('get.selval');
		
		$p=I('p')?I('p'):1;
		$listrows=20;
		$firstrow=($p-1)*$listrows;
		
		$map=[];
		if(!empty($param['goods_no'])){
			$goods_no=$param['goods_no'];
			$map['g.goods_no'] = array('like','%'.$goods_no.'%');
		}
		if(!empty($param['goods_name'])){
			$goods_name=$param['goods_name'];
			$map['g.goods_name'] = array('like','%'.$goods_name.'%');
		}
		if(!empty($param['bar_code'])){
			$bar_code=$param['bar_code'];
			$map['g.bar_code'] = array('like','%'.$bar_code.'%');
		}
		if(!empty($param['merchant_code'])){
			$merchant_code=$param['merchant_code'];
			$map['o.old_merchant_code']=['like',"%$merchant_code%"];
		}
		if(!empty($param['order_no'])){
			$order_no=$param['order_no'];
			$map['o.order_no']=['like',"%$order_no%"];
		}
		
		if(!empty($param['own_status'])){
			$map['o.own_status']=1;
		}
		$count=$m->alias('g')->join("__MOVEGOODS__ o on g.order_id=o.id")->where($map)->count();
		$list=$m->field("o.order_no,o.old_merchant_code,g.goods_no,g.goods_name,g.bar_code,g.amount,g.remark,g.manua_id")->alias('g')->join("__MOVEGOODS__ o on g.order_id=o.id")->where($map)->limit($firstrow.','.$listrows)->order('o.id desc')->select();
		// echo $m->_sql();
		
		$excel=I('excel');
		if($excel){
			$list=$m->field("o.order_no,o.old_merchant_code,g.goods_no,g.goods_name,g.bar_code,g.amount,g.remark,g.manua_id")->alias('g')->join("__MOVEGOODS__ o on g.order_id=o.id")->where($map)->order('o.id desc')->select();
			foreach($list as $ks=>$vs){
				$list['rows'][$ks]['goods_no']=' '.$vs['goods_no'];
				$list['rows'][$ks]['manua_id']=' '.$vs['manua_id'];
				$list['rows'][$ks]['bar_code']=' '.$vs['bar_code'];
				$list['rows'][$ks]['old_merchant_code']=' '.$vs['old_merchant_code'];
			}
			$xlsName  = "调拨明细列表";
			$xlsCell  = array(
				array('order_no','订单编号'),
				array('old_merchant_code','请求调拨货主编码'),
				array('goods_no','商品编码'),
				array('goods_name','商品名称'),
				array('bar_code','条形码'),
				array('amount','总数量'),
			);
			$Aexcel=A('Order');
			$Aexcel->exportExcel($xlsName,$xlsCell,$list);
			die;
		}
		$Page       = new \Think\Page($count,$listrows);// 实例化分页类 传入总记录数和每页显示的记录数(25)
		$show       = $Page->show();// 分页显示输出
		
		$this->assign("count",$count);
		$this->assign("list",$list);
		$this->assign('page',$show);// 赋值分页输出
		$this->display();
    }
	
    public function lists(){
		$g=session('company');
        $user_id=$g['company_id'];
		$group_id=M("user_warehouse")->where(array('user_id'=>$user_id))->getField('warehouse_group_id');
        $group_id=explode(',',$group_id);
        $where['id']=array('in',$group_id);
        $warehouse_list=M("warehouse")->field('id,warehouse_code,name')->where($where)->select();
		
        $m=M('Movegoods', C('DB_PREFIX_T'), C('DB_TYPE') . '://' . C('DB_USER') . ':' . C('DB_PWD') . '@' . C('DB_HOST') . ':' . C('DB_PORT') . '/' . C('erp_dbname'));
		
		$keywords=I('get.keywords');     
		$selval=I('get.selval');     
		$p=I('p')?I('p'):1;
		$listrows=20;
		$firstrow=($p-1)*$listrows;
        if(!empty($keywords)){
			if($selval=='1'){
				$map['order_no'] = array('like','%'.$keywords.'%');
			}
        }
		$count=$m->where($map)->count();
		$list=$m->where($map)->limit($firstrow.','.$listrows)->order('id desc')->select();
		$Page       = new \Think\Page($count,$listrows);// 实例化分页类 传入总记录数和每页显示的记录数(25)
		$show       = $Page->show();// 分页显示输出
		foreach($list as $k=>$v){
			if(!empty($v['old_merchant_code'])){
				$list[$k]['old_merchant_name']=M('User')->where(['owner_code'=>$v['old_merchant_code']])->getField('company');
			}
		}
		
		$this->assign("warehouse_list",$warehouse_list);
		$this->assign("count",$count);
		$this->assign("list",$list);
		$this->assign('page',$show);// 赋值分页输出
		$this->display();
    }
	//添加
	function add_configs(){
			$m=M('Movegoods', C('DB_PREFIX_T'), C('DB_TYPE') . '://' . C('DB_USER') . ':' . C('DB_PWD') . '@' . C('DB_HOST') . ':' . C('DB_PORT') . '/' . C('erp_dbname'));
			$param = I('param.','','trim');
			$param['add_time']=time();
			$param['own_status']=1;
			// echo $m->getlastsql();
			$res=$m->add($param);
			if($res){
				$this->success('添加成功');
			}
	}
	//更新
	function add_config(){
		$m=M('Movegoods',C('DB_PREFIX_T'),C('DB_TYPE') . '://' . C('DB_USER') . ':' . C('DB_PWD') . '@' . C('DB_HOST') . ':' . C('DB_PORT') . '/' . C('erp_dbname'));
		$this->tslist();
		if(IS_POST){
			$param = I('param.','','trim');
			$param['update_time'] = time();
			$id=$param['id'];
			$res=$m->where(array('id'=>$id))->save($param);
			if($res!==false){
				$this->success('更新成功');
			}
		}else{
			$this->display();
		}
	}
	//编辑
	function edit_config(){
		$this->tslist();
		$id=trim(I('id'));
		$m=M('Movegoods', C('DB_PREFIX_T'), C('DB_TYPE') . '://' . C('DB_USER') . ':' . C('DB_PWD') . '@' . C('DB_HOST') . ':' . C('DB_PORT') . '/' . C('erp_dbname'));
		$detail=$m->where(array('id'=>$id))->find();
		$this->assign('detail',$detail);
		$this->display();
	}
	//删除
	function del_config(){
		$id=trim(I('id'));
		$m=M('Movegoods', C('DB_PREFIX_T'), C('DB_TYPE') . '://' . C('DB_USER') . ':' . C('DB_PWD') . '@' . C('DB_HOST') . ':' . C('DB_PORT') . '/' . C('erp_dbname'));
		$map['id']=$id;
		$info=$m->where($map)->find();
		if($info['status']==1){
			echo "已审核通过不能删除";
			die;
		}
		if($info['push_status']==1){
			echo "已推送不能删除";
			die;
		}
		$status=$m->where($map)->delete();

		if($status!==false){
            echo "y";
        }else{
            echo "操作失败";
        }
	}
}